package com.tianhui.consignortwofei.pattern.orderOprate;

import android.content.Context;

import com.fgs.common.CommonModel;
import com.fgs.common.CommonResponse;
import com.fgs.common.api.CommonConfig;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.ToastUtil;
import com.tianhui.consignortwofei.api.OrderApiService;
import com.tianhui.consignortwofei.constant.OrderType;

import java.util.Map;

/**
 * @author fgs
 * @date 2020/8/29
 * @description
 **/
public class OrderRequestOperate {
    public OrderRequestOperate() {
    }

    public void orderOperateRequest(Context context, Map<String, String> map, int dingJinType,OrderOperateCallback orderOperateCallback) {
        if (OrderType.TYPE_SOURCE_DINGJIN==dingJinType) {//区分有无订金
            new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).orderOperateDingJin(map), new ObserverResponseListener<CommonResponse>() {
                @Override
                public void onNext(CommonResponse commonResponse) {
                    if (commonResponse.getCode() == 20000) {
                        if (orderOperateCallback != null) {
                            orderOperateCallback.operateCallback();
                        }
                    } else {
                        ToastUtil.showShortToast(commonResponse.getMsg());
                    }
                }

                @Override
                public void onError(ExceptionHandle.ResponseThrowable e) {
                    ToastUtil.showShortToast(e.message);
                }
            });
        }else {
            new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).orderOperate(map), new ObserverResponseListener<CommonResponse>() {
                @Override
                public void onNext(CommonResponse commonResponse) {
                    if (commonResponse.getCode() == 20000) {
                        if (orderOperateCallback != null) {
                            orderOperateCallback.operateCallback();
                        }
                    } else {
                        ToastUtil.showShortToast(commonResponse.getMsg());
                    }
                }

                @Override
                public void onError(ExceptionHandle.ResponseThrowable e) {
                    ToastUtil.showShortToast(e.message);
                }
            });
        }
    }



    public void orderBeiZhuRequest(Context context, Map<String, String> map, int dingJinType,OrderOperateCallback orderOperateCallback) {


            new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).orderAdjust(map), new ObserverResponseListener<CommonResponse>() {
                @Override
                public void onNext(CommonResponse commonResponse) {
                    if (commonResponse.getCode() == 20000) {
                        if (orderOperateCallback != null) {
                            orderOperateCallback.operateCallback();
                        }
                    } else {
                        ToastUtil.showShortToast(commonResponse.getMsg());
                    }
                }

                @Override
                public void onError(ExceptionHandle.ResponseThrowable e) {
                    ToastUtil.showShortToast(e.message);
                }
            });

    }


    public void sureExternalRequest(Context context, Map<String, String> map, int dingJinType,OrderOperateCallback orderOperateCallback) {


        new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).sureExternalRequest(map), new ObserverResponseListener<CommonResponse>() {
            @Override
            public void onNext(CommonResponse commonResponse) {
                if (commonResponse.getCode() == 20000) {
                    if (orderOperateCallback != null) {
                        orderOperateCallback.operateCallback();
                    }
                } else {
                    ToastUtil.showShortToast(commonResponse.getMsg());
                }
            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                ToastUtil.showShortToast(e.message);
            }
        });

    }




    public void ZhuanZhaoChe(Context context, Map<String, String> map, int dingJinType,OrderOperateCallback orderOperateCallback) {

        new CommonModel().subscribe(context, CommonConfig.getInstance().create(OrderApiService.class).orderOperate(map), new ObserverResponseListener<CommonResponse>() {
            @Override
            public void onNext(CommonResponse commonResponse) {
                if (commonResponse.getCode() == 20000) {
                    if (orderOperateCallback != null) {
                        orderOperateCallback.operateCallback();
                    }
                } else {
                    ToastUtil.showShortToast(commonResponse.getMsg());
                }
            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                ToastUtil.showShortToast(e.message);
            }
        });



    }



}
